package com.atguigu.lease.sustom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.function.Predicate;

/**
 * @ClassName StringToItemTypeConverter
 * @Author admin
 * @Date 2024/5/29
 *
 * 单个converter,被StringToBaseEnumConverterFactory替换
 *
 */
//@Component
@Deprecated
public class StringToItemTypeConverter implements Converter<String, ItemType> {

    @Override
    public ItemType convert(String source) {
        return Arrays.stream(ItemType.values()).filter(new Predicate<ItemType>() {
            @Override
            public boolean test(ItemType itemType) {
                return source.equals(String.valueOf(itemType.getCode()));
            }
        }).findFirst().orElseThrow(IllegalArgumentException::new);
    }















}
